{% load humanize %}
{% load helpers %}
{% load i18n %}

<p>
  {% if job.started %}
    {% trans "Started" %}: <strong>{{ job.started|annotated_date }}</strong>
  {% elif job.scheduled %}
    {% trans "Scheduled for" %}: <strong>{{ job.scheduled|annotated_date }}</strong> ({{ job.scheduled|naturaltime }})
  {% else %}
    {% trans "Created" %}: <strong>{{ job.created|annotated_date }}</strong>
  {% endif %}
  {% if job.completed %}
    {% trans "Duration" %}: <strong>{{ job.duration }}</strong>
  {% endif %}
  <span id="pending-result-label">{% badge job.get_status_display job.get_status_color %}</span>
</p>
{% if job.completed %}
  <div class="card">
    <h5 class="card-header">{% trans "Report Methods" %}</h5>
    <div class="card-body">
      <table class="table table-hover">
        {% for method, data in job.data.items %}
          <tr>
            <td class="font-monospace"><a href="#{{ method }}">{{ method }}</a></td>
            <td class="text-end report-stats">
              <span class="badge bg-success">{{ data.success }}</span>
              <span class="badge bg-info">{{ data.info }}</span>
              <span class="badge bg-warning">{{ data.warning }}</span>
              <span class="badge bg-danger">{{ data.failure }}</span>
            </td>
          </tr>
        {% endfor %}
      </table>
    </div>
  </div>
  <div class="card">
    <h5 class="card-header">{% trans "Report Results" %}</h5>
    <div class="card-body">
      <table class="table table-hover report">
        <thead>
          <tr class="table-headings">
            <th>{% trans "Time" %}</th>
            <th>{% trans "Level" %}</th>
            <th>{% trans "Object" %}</th>
            <th>{% trans "Message" %}</th>
          </tr>
        </thead>
        <tbody>
          {% for method, data in job.data.items %}
            <tr>
              <th colspan="4" style="font-family: monospace">
                <a name="{{ method }}"></a>{{ method }}
              </th>
            </tr>
            {% for time, level, obj, url, message in data.log %}
              <tr class="{% if level == 'failure' %}danger{% elif level %}{{ level }}{% endif %}">
                <td>{{ time }}</td>
                <td>
                  <label class="badge bg-{% if level == 'failure' %}danger{% else %}{{ level }}{% endif %}">{{ level|title }}</label>
                </td>
                <td>
                  {% if obj and url %}
                    <a href="{{ url }}">{{ obj }}</a>
                  {% elif obj %}
                    {{ obj }}
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                </td>
                <td class="rendered-markdown">{{ message|markdown }}</td>
              </tr>
            {% endfor %}
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
{% elif job.started %}
  {% include 'extras/inc/result_pending.html' %}
{% endif %}
